package com.ant.storage.controller;

import com.ant.storage.service.IUserService;
import com.ant.storage.common.ResultVo;
import com.ant.storage.utils.DingDingUtil;
import com.taobao.api.ApiException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/User")
@Api(tags = "员工接口")
public class UserController {

    @Autowired
    IUserService userService;

    @ApiOperation(value = "获取员工列表")
    @GetMapping("/queryUserList")
    public ResultVo queryUserList(){
        return ResultVo.success("ok",userService.list());
    }

    @ApiOperation(value = "查询员工详情")
    @GetMapping("/getDepId")
    public ResultVo getDepId() throws ApiException {
        DingDingUtil.queryDeptId();
        return ResultVo.success("ok");
    }


    @ApiOperation(value = "查询员工详情")
    @GetMapping("/getUserId/{tel}")
    public ResultVo getUserId(@PathVariable("tel") String tel) throws ApiException {
        String str = DingDingUtil.queryUserId(tel);
        return ResultVo.success("ok",str);
    }

    @ApiOperation(value = "更新员工列表")
    @GetMapping("/updateUserList")
    @Transactional(rollbackFor = Exception.class)
    public ResultVo updateUserList() throws ApiException {
        userService.addDeptId();
        userService.updateUser();
        return ResultVo.success("ok");
    }

    @ApiOperation(value = "查询员工详情")
    @GetMapping("/queryUser")
    public ResultVo queryUser(String user_name,String user_mobile) throws ApiException {
        return userService.queryUser(user_name,user_mobile);
    }

    @ApiOperation(value = "查询员工详情")
    @GetMapping("/queryUserOne")
    public ResultVo queryUserOne(String userId) throws ApiException {
        return userService.queryUserOne(userId);
    }

}
